package com.lin.cloud.disk.controller;


import com.lin.cloud.disk.common.utils.Result;
import com.lin.cloud.disk.entity.pojo.Directory;
import com.lin.cloud.disk.entity.request.directory.*;
import com.lin.cloud.disk.entity.response.GetCurrentDirectoryAndFileListResponse;
import com.lin.cloud.disk.entity.response.GetSpecifiedDayWithinFileAndDirectoryByDeleteResponse;
import com.lin.cloud.disk.manage.IDirectoryManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ljc
 * @date 2020/12/30 23:42
 */
@RestController
@RequestMapping("/api/directory")
@Slf4j
@Api(tags = "目录服务类")
public class DirectoryController {

    @Resource
    private IDirectoryManageService directoryManageService;

    @PostMapping(value = "/create")
    @ApiOperation(value = "创建目录")
    public Result createDirectory(@RequestBody @Validated CreateDirectoryRequest request) {
        directoryManageService.createDirectory(request);
        return Result.success();
    }

    @PostMapping(value = "/getDirectoryPath")
    @ApiOperation(value = "获取目录结构")
    public Result<List<Directory>> getDirectoryPath(@RequestBody @Validated GetDirectoryPathRequest request) {
        List<Directory> directoryPath = directoryManageService.getDirectoryPath(request);
        return Result.success(directoryPath);
    }

    @PutMapping(value = "/updateDirectoryName")
    @ApiOperation(value = "修改目录名字")
    public Result updateDirectoryName(@RequestBody @Validated UpdateDirectoryNameRequest request) {
        directoryManageService.updateDirectoryName(request);
        return Result.success();
    }

    @DeleteMapping(value = "/logicRemoveDirectory")
    @ApiOperation(value = "逻辑删除目录")
    public Result logicRemoveDirectory(@RequestBody @Validated RemoveDirectoryRequest request) {
        directoryManageService.logicRemoveDirectory(request);
        return Result.success();
    }


    @DeleteMapping(value = "/physicistRemoveDirectory")
    @ApiOperation(value = "物理删除目录")
    public Result physicistRemoveDirectory(@RequestBody @Validated RemoveDirectoryRequest request) {
        directoryManageService.physicistRemoveDirectory(request);
        return Result.success();
    }


    @PostMapping(value = "/logicRestoreDirectory")
    @ApiOperation(value = "逻辑恢复目录")
    public Result logicRestoreDirectory(@RequestBody @Validated RestoreDirectoryRequest request) {
        directoryManageService.logicRestoreDirectory(request);
        return Result.success();
    }

    @PutMapping(value = "/moveDirectory")
    @ApiOperation(value = "移动目录")
    public Result moveDirectory(@RequestBody @Validated MoveDirectoryRequest request) {
        directoryManageService.moveDirectory(request);
        return Result.success();
    }


    @PostMapping(value = "/getCurrentDirectoryAndFileList")
    @ApiOperation(value = "获取当前目录下的文件与目录")
     public Result<GetCurrentDirectoryAndFileListResponse> getCurrentDirectoryAndFileList(@RequestBody @Validated GetCurrentDirectoryAndFileListRequest request){
         GetCurrentDirectoryAndFileListResponse response = directoryManageService.getCurrentDirectoryAndFileList(request);
         return Result.success(response);
     }


    @PostMapping(value = "/getSpecifiedDayWithinFileAndDirectoryByDelete")
    @ApiOperation(value = "获取指定时间内删除的文件与目录")
    public Result<GetSpecifiedDayWithinFileAndDirectoryByDeleteResponse> getSpecifiedDayWithinFileAndDirectoryByDelete(@RequestBody @Validated GetSpecifiedDayWithinFileAndDirectoryByDeleteRequest request){
        GetSpecifiedDayWithinFileAndDirectoryByDeleteResponse response = directoryManageService.getSpecifiedDayWithinFileAndDirectoryByDelete(request);
        return Result.success(response);
    }


    @PostMapping(value = "/getLazyDirectoryTree")
    @ApiOperation(value = "懒加载获取目录树")
    public Result<List<Directory>> getLazyDirectoryTree(@RequestBody @Validated GetLazyDirectoryTreeRequest request){
        List<Directory> response = directoryManageService.getLazyDirectoryTree(request);
        return Result.success(response);
    }



}
